<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
    <link rel="stylesheet" href="../../styles/common.css" />
    <link rel="stylesheet" href="../../styles/page.css" />
    <style>
        #judge-app  .notAdmin::after{
            border: 0 !important;

        }
    </style>
    <style scoped>
        fieldset {

            /* 表单页面居中，宽度50% ,legend颜色设置，legend圆角*/
            border:2px solid #DCDFE6;  text-align:left; border-radius: 8px;margin: 0 auto;width:50%;
        }
    </style>
</head>
<body>
<div class="addBrand-container" id="judge-app">
    <el-row style="text-align: center">
            <el-form
                    ref="ruleForm"
                    :model="ruleForm"
                    :rules="rules"
                    :inline="false"
                    label-width="150px"
                    class="demo-ruleForm"
                    label-position="left"
                    style="display: inline-block"
            >
                <el-form-item label="教学活动质量:" prop="teachingActivities" >
                    <el-input v-model="ruleForm.teachingActivities" placeholder="请输入1-5的数字" maxlength="10"/>
                </el-form-item>
                <el-form-item label="学时分配:" prop="allocationOfStudyTime">
                    <el-input v-model="ruleForm.allocationOfStudyTime" placeholder="请输入1-5的数字" maxlength="10"/>
                </el-form-item>
                <el-form-item label="资源贡献:" prop="resourceContribution">
                    <el-input v-model="ruleForm.resourceContribution" placeholder="请输入1-5的数字" maxlength="10"/>
                </el-form-item>
                <div class="subBox address" style="display: inline-block">
                    <el-form-item>
                        <el-button  @click="goBack()">
                            取消
                        </el-button>
                        <el-button
                                type="primary"
                                @click="submitForm('ruleForm')"
                        >
                            提交
                        </el-button>
                    </el-form-item>
                </div>
            </el-form>
    </el-row>
</div>
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/teacher.js"></script>
<script src="../../js/validate.js"></script>
<script src="../../js/index.js"></script>
<script>
    new Vue({
        el: '#judge-app',
        data() {
            return {
                id: '',
                actionType : '',
                teacherId:'',
                checkList: [],
                teachingActivities:'',
                allocationOfStudyTime:'',
                resourceContribution:'',
                ruleForm : {
                    'teachingActivities': '',
                    'allocationOfStudyTime': '',
                    'resourceContribution': '',

                }
            }
        },
        computed: {
            rules () {
                return {
                    //账号
                    teachingActivities:[{required:true, 'validator':checkNum,trigger:'blur'}],
                    allocationOfStudyTime:[{'required':true,'validator':checkNum,'trigger':'blur'}],
                    resourceContribution:[{required:true,'validator':checkNum,trigger:'blur'}],
                }
            }
        },
        created() {
            this.id = requestUrlParam('id')
            this.actionType = this.id ? 'edit' : 'add'
            if (this.id) {
                this.init()
            }
        },
        mounted() {
        },
        methods: {
            async init () {
                queryTeacherById(this.id).then(res => {
                    console.log(res)
                    if (String(res.code) === '1') {
                        console.log(res.data)
                        this.ruleForm = res.data
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                })
            },
            submitForm (formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                            const params = {
                                teacherId:this.id,
                                teachingActivities:this.ruleForm.teachingActivities,
                                allocationOfStudyTime:this.ruleForm.allocationOfStudyTime,
                                resourceContribution:this.ruleForm.resourceContribution
                            }
                        subTeaJudge(params).then(res => {
                                if (res.code === 1) {
                                    this.$message.success('评价成功！')
                                    this.goBack()
                                } else {
                                    this.$message.error(res.msg || '操作失败')
                                }
                            }).catch(err => {
                                this.$message.error('请求出错了：' + err)
                            })
                    } else {
                        console.log('error submit!!')
                        return false
                    }
                })
            },
            goBack(){
                window.parent.menuHandle({
                    id: '3',
                    url: '/backend/page/teacher/judge.html',
                    name: '评价老师'
                },false)
            }
        }
    })
</script>
</body>
</html>